﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace Module.QuanTriHeThong.HeThong
{
    public class LichSuHeThong : DBInteractionBase
    {

        public DataTable SelectAll(string tukhoa, DateTime tungay, DateTime denngay, int pageindex, int pagesize, out int recordcount)
        {
            var dt = new DataSet();
            try
            {
                using (var dbcmd = new SqlCommand("LichSuHoatDong_SelectAll", GetConnection()))
                {
                    dbcmd.CommandType = CommandType.StoredProcedure;
                    dbcmd.Parameters.Add(new SqlParameter("@TuKhoa",
                        string.IsNullOrEmpty(tukhoa) ? "" : tukhoa));
                    dbcmd.Parameters.Add(new SqlParameter("@TuNgay", tungay));
                    dbcmd.Parameters.Add(new SqlParameter("@DenNgay", denngay));
                    dbcmd.Parameters.Add(new SqlParameter("@PageIndex", pageindex));
                    dbcmd.Parameters.Add(new SqlParameter("@PageSize", pagesize));
                    dbcmd.Parameters.Add(new SqlParameter("@RecordCount", SqlDbType.Int, 50)
                    {
                        Direction = ParameterDirection.Output
                    });
                    var dtAdapter = new SqlDataAdapter(dbcmd);
                    dtAdapter.Fill(dt);
                    recordcount = Convert.ToInt32(dbcmd.Parameters["@RecordCount"].Value);
                    return dt.Tables[0];
                }
            }
            catch (Exception ex)
            {
                throw new Exception("LichSuHeThong_SelectAll: " + ex.Message);
            }
        }
    }
}
